layui.use(['layer', 'form', 'admin', 'ax', 'dict', 'laydate', 'upload', 'layedit', 'xmSelect'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var dict = layui.dict;
    var upload = layui.upload;//获取自定义模块
    var layedit = layui.layedit;
    var xmSelect = layui.xmSelect;
    var laydate = layui.laydate;


    dict.renderDictAll(); //渲染

    //table的初始化实例
    //获取详细信息
    var ajax = new $ax(Feng.ctxPath + "/erya/costing/costingDetail/" + decodeURI(escape(Feng.getUrlParam("id"))));
    var result = ajax.start();
    console.log('testttt' +　result.data)
    form.val('costingFrom', result);
    //重新渲染select数据
    form.render('select');
    $('#costingDate').val(result.data.costingDate);
    $('#rawMaterialCost').val(result.data.rawMaterialCost);
    $('#artificialCost').val(result.data.artificialCost);
    $('#packageCost').val(result.data.packageCost);
    $('#relationshipCost').val(result.data.relationshipCost);
    $('#operationCost').val(result.data.operationCost);
    $('#orderAllIncome').val(result.data.orderAllIncome);
    $('#id').val(result.data.id);



    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        data.field.costingDate = $('#costingDate').val();
        data.field.rawMaterialCost = $('#rawMaterialCost').val();
        data.field.artificialCost = $('#artificialCost').val();
        data.field.packageCost = $('#packageCost').val();
        data.field.relationshipCost = $('#relationshipCost').val();
        data.field.operationCost = $('#operationCost').val();
        data.field.orderAllIncome = $('#orderAllIncome').val();
        data.field.id = $('#id').val();


        layer.load(0, {
            shade: [0.3, '#393D49'],
        }); //上传loading
        $.ajax({
            url: Feng.ctxPath + "/erya/costing/costingUpdate",
            type: "post", // 请求类型
            data: data.field,
            dataType: 'json',
            async: true, // 是否异步
            success: function (data) {
                if(data.code===200){
                    Feng.success("修改成功！");
                    //传给上个页面，刷新table用
                    admin.putTempData('formOk', true);
                    //关掉对话框
                    admin.closeThisDialog();
                }else {
                    console.log(data.message,"失败")
                    layer.open({title: '失败', content: ''+data.message});
                    layer.closeAll('loading'); //关闭loading
                }
            },
            error: function (data) {
                layer.closeAll('loading');
                Feng.error("修改失败！" + data.responseJSON.message)
            }
        });

        //添加 return false 可成功跳转页面
        return false;
    });
});